const doctor = require('../service/doctor')

// 删除
const doctorListDelet = async(ctx)=>{
    let res = await doctor.doctorListDelete(ctx.query)
    if(res.affectedRows > 0){
        return ctx.body = {
            code: 20000,
            msg: '删除成功'
        }
    }else{
        return ctx.body = {
            code: 40001,
            msg: '删除失败'
        }
    }
}

// 新增
const doctorListAdd = async(ctx)=>{
    let res = await doctor.doctorListAdd(ctx.request.body)
    if(res.affectedRows > 0){
        return ctx.body = {
            code: 20000,
            msg: '新增成功'
        }
    }else{
        return ctx.body = {
            code: 40001,
            msg: '新增失败'
        }
    }
}

// 编辑
const doctorListEdit = async(ctx)=>{
    let res = await doctor.doctorListUpdate(ctx.request.body)
    if(res.affectedRows > 0){
        return ctx.body = {
            code: 20000,
            msg: '编辑成功'
        }
    }else{
        return ctx.body = {
            code: 40001,
            msg: '编辑失败'
        }
    }
}

// 服务过我的医生
const doctorListService = async(ctx)=>{
    let res = await doctor.doctorServiceList(ctx.query)
    if(res.length > 0){
        return ctx.body = {
            code: 20000,
            msg: '查询成功',
            data: res
        }
    }else{
        return ctx.body = {
            code: 40001,
            msg: '查询失败'
        }
    }
}

// 新增服务过我的医生
const doctorListServiceAdd = async(ctx)=>{
    let res = await doctor.doctorServiceAdd(ctx.request.body)
    if(res.affectedRows > 0){
        return ctx.body = {
            code: 20000,
            msg: '新增成功'
        }
    }else{
        return ctx.body = {
            code: 40001,
            msg: '新增失败'
        }
    }
}

// 浏览量
const doctorListBrowse = async(ctx)=>{
    let res = await doctor.doctorBrowse(ctx.request.body)
    if(res.affectedRows > 0){
        return ctx.body = {
            code: 20000,
            msg: '浏览量增加成功'
        }
    }
}

module.exports = {
    doctorListDelet,
    doctorListAdd,
    doctorListEdit,
    doctorListService,
    doctorListServiceAdd,
    doctorListBrowse
}